package com.hsgene.order.constants.v1;

/**
 * 订单状态枚举
 *
 * @author wangbing
 * @version 1.0, 2018/9/18
 */
public enum OrderStatus {

    /**
     * 提交订单
     */
    INIT(1, "init", "新订单"),

    /**
     * 地服确认=>客服确认(地管确认)
     */
    DIFU_CONFIRMED(2, "difu_confirmed", "待地管确认"),

    /**
     * 初审通过=>地服完成
     */
    @Deprecated
    PRE_AUDIT_PASS(3, "pre_audit_pass", "预审核通过"),

    /**
     * 初审不通过
     */
    @Deprecated
    PRE_AUDIT_FAIL(4, "pre_audit_fail", "预审核不通过"),

    /**
     * 地服收款完成=》收款确认
     */
    @Deprecated
    DIFU_COMPLETED(5, "difu_completed", "地服收款完成"),

    /**
     * 地服确认收款完成=》样本确认
     */
    @Deprecated
    AUDIT_PASS(6, "audit_pass", "地服收款确认完成"),

    /**
     * 样本待确认
     */
    WAIT_SAMPLE_CONFIRM(7, "wait_sample_confirm", "样本待确认"),

    /**
     * 样本已确认
     */
    @Deprecated
    SAMPLE_CONFIRMED(8, "sampled_confirmed", "样本已确认"),

    /**
     * 检测中=>回款
     */
    TESTING(9, "testing", "报告待上传"),

    /**
     * 回款确认=>上传报告
     */
    @Deprecated
    RECEIVE_PAYMENT_CONFIRMED(10, "receive_payment_confirmed", "回款确认"),

    /**
     * 报告已上传=>申请开票
     */
    @Deprecated
    REPORTED(11, "reported", "报告已上传"),

    /**
     * 开票确认=》审核发放【申请开票】
     */
    @Deprecated
    APPLY_BILL(12, "apply_bill", "申请开票"),

    /**
     * 开票确认=》审核发放
     */
    BILL_CONFIRMED(13, "bill_confirmed", "开票确认"),

    /**
     * 邮寄
     */
    MAIL(14, "mail", "待签收材料"),

    /**
     * 完成
     */
    DONE(15, "done", "完成"),
    /**
     * 待完善订单(物流、样本、耗材)
     */
    WAIT_PERFECTED(16, "wait_perfected", "订单待完善"),
    /**
     * 待收款
     */
    WAIT_RECEIPT_MONEY(17, "wait_receipt_money", "待收款"),
    /**
     * 待收款待分配
     */
    WAIT_RECEIPT_DISTRIBUTION(18, "wait_receipt_distribution", "待收款待分配"),
    /**
     * 收款待分配
     */
    PERFECTED_DISTRIBUTION(19, "receipt_distribution", "收款待分配"),
    /**
     * 报告待审核
     */
    PAID_FOR(20, "paid_for", "报告待审核"),

    /**
     * 待机构寄送
     */
    PENDING_PAYMENT(21, "pending_payment", "待机构寄送"),
    /**
     * 待寄送至地服
     */
    WAIT_AGENCY_SEND(22, "wait_agency_send", "待寄送至地服"),
    /**
     * 待发货
     */
    WAIT_SHIP(23, "wait_ship", "待发货"),
    /**
     * 待收货
     */
    WAIT_RECEIPT_GOODS(24, "wait_receipt_goods", "待收货"),
    /**
     * 待评价
     */
    WAIT_COMMENT(25, "wait_comment", "待评价"),
    /**
     * 待地服签收
     */
    WAIT_DIFU_SIGNING(26, "wait_difu_signing", "待地服签收"),
    /**
     * 待付款过期关闭
     */
    ORDER_CLOSE(27, "order_close", "已关闭"),

    /**
     * 退款待审核
     */
    WAIT_REFUND_AUDIT(28, "wait_refund_audit", "退款待审核"),

    /**
     * 退款通过
     */
    REFUND_ACCESS(29, "refund_access", "退款成功"),

    /**
     * 退款拒绝
     */
    REFUND_REJECT(30, "refund_reject", "退款拒绝"),

    /**
     * 地管拒绝待修改
     */
    REFUSE_EDIT(31, "refuse_edit", "拒绝待修改"),
    /**
     * 异常
     */
    EXCEPTION(97, "exception", "异常"),
    /**
     * 已取消
     */
    CANCELED(98, "canceled", "已取消"),
    /**
     * 暂停
     */
    @Deprecated
    STOP(99, "stop", "暂停"),
    /************************订单费用状态start****************************/
    ORDER_INIT(1001, "init", "未付款"),
    ORDER_CHARGED(1002, "charged", "已付款"),
    ORDER_CONFIRMED(1003, "confirmed", "已确认"),
    /************************订单费用状态end****************************/

    UNDEFINED(-2, "undefined", "undefined");

    private final int code;

    private final String value;

    private final String desc;

    OrderStatus(int code, String value, String desc) {
        this.code = code;
        this.value = value;
        this.desc = desc;
    }

    public static OrderStatus getEnum(String value) {
        for (OrderStatus status : values()) {
            if (status.value.equals(value)) {
                return status;
            }
        }

        return UNDEFINED;
    }

    public static OrderStatus getEnum(int code) {
        for (OrderStatus status : values()) {
            if (status.code == code) {
                return status;
            }
        }

        return UNDEFINED;
    }

    /**
     * 是否可以线上支付
     *
     * @return true：可以；false：不可以
     */
    public boolean canPayOnline() {
        return this.equals(WAIT_RECEIPT_MONEY) || this.equals(WAIT_RECEIPT_DISTRIBUTION);
    }

    /**
     * 根据状态判断订单是否无效
     * ORDER_CLOSE || EXCEPTION || CANCELED -> 无效
     *
     * @return true：有效的订单；false：无效的订单
     */
    public boolean isValid() {
        return !(this.equals(ORDER_CLOSE) || this.equals(EXCEPTION) || this.equals(CANCELED) || this.equals(UNDEFINED));
    }

    /**
     * 是否可以申请退款
     * 只有：待地管确认--样本待确认--报告待上传可以申请退款
     *
     * @return true：可以申请退款；false：不可以申请退款
     */
    public boolean canRefund() {
        return this.equals(DIFU_CONFIRMED) || this.equals(WAIT_SAMPLE_CONFIRM) || this.equals(TESTING);
    }

    /**
     * 订单是否关闭
     *
     * @return true：未支付超时关闭，false：未关闭
     */
    public boolean isClosed() {
        return this.equals(ORDER_CLOSE);
    }

    /**
     * canShowCompleteBtn这个字段现在的逻辑是，用于控制只有在待地管确认、待确认样本、待上传报告、报告已上传、待审核四个状态下才可以完善
     * 上述是花生仁的原逻辑，因子网没有报告已上传状态
     *
     * @return canShowCompleteBtn
     */
    public boolean canShowCompleteBtn() {
        return this.equals(WAIT_SAMPLE_CONFIRM)||this.equals(DIFU_CONFIRMED) || this.equals(TESTING) || this.equals
                (PAID_FOR);
    }

    public int getCode() {
        return code;
    }

    public String getValue() {
        return value;
    }

    public String getDesc() {
        return desc;
    }


}
